

// pages/orders/orders.js
const app = getApp();

const utils = require('../../utils/utils')


Page({

  /**
   * 页面的初始数据
   */
  data: {
    OPEN_ID: '',
    CUSTOMER_ID: '',
    ticket: [],//所有数据
    time_quan: '',
    VALID: '',
    session_key:'',

  },


  back(){
    wx.switchTab({
      url: '../../pages/personage/personage',
    })
  },


  quanwang(){
    wx.navigateTo({
      url: '../../pages/shequtuangou/shequtuangou'
    })
  
  },




  


  search() {
    this.setData({
      OPEN_ID: app.globalData.openid,
      CUSTOMER_ID: app.globalData.CUSTOMER_ID
    });
    wx.request({
      url: app.globalData.interface+'/goods/API_9819_selectMyGoodsTuanGouList',
      method: 'POST',
      data: {
        OPEN_ID: this.data.OPEN_ID,

        CUSTOMER_ID: this.data.CUSTOMER_ID, 
   
        session_key:this.data.session_key,
        OPEN_UUID:this.data.jiami

      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {

        console.log(res.data.data);
        const shusp = res.data.data
        const liscop = shusp.map((item) => {
          console.log(item);
          if (item.PAYMENT_TIME == '') {
            return {
              ...item,
              PAYMENT_TIME: item.PAYMENT_TIME
            }
          }else{
            return {
              ...item,
              PAYMENT_TIME: utils.formatDate(item.PAYMENT_TIME)
            }
          }
        })
        console.log(liscop);

        this.setData({
          ticket: liscop,

        })
      }
    })
  },



  // search() {
  //   this.setData({
  //     OPEN_ID: app.globalData.openid,
  //     CUSTOMER_ID: app.globalData.CUSTOMER_ID
  //   });
  //   wx.request({
  //     url: app.globalData.interface+'/newVersion/API_2017_myExchangeGoods',
  //     method: 'POST',
  //     data: {
  //       OPEN_ID: this.data.OPEN_ID,
  //       CUSTOMER_ID: this.data.CUSTOMER_ID,
  //       VALID:this.data.VALID,
        
  //       OPEN_ID: this.data.openid, //用户OPEN_ID
  //       session_key:this.data.session_key,
  //       OPEN_UUID:this.data.jiami

  //     },
  //     header: {
  //       'content-type': 'application/x-www-form-urlencoded'
  //     },
  //     success: res => {
  //       const shusp = res.data.data
  //       const liscop = shusp.map((item) => {
  //         console.log(item);
  //         if (item.PAYMENT_TIME == '') {
  //           return {
  //             ...item,
  //             PAYMENT_TIME: item.PAYMENT_TIME
  //           }
  //         }else{
  //           return {
  //             ...item,
  //             PAYMENT_TIME: utils.formatDate(item.PAYMENT_TIME)
  //           }
  //         }
  //       })
  //       console.log(liscop);

  //       this.setData({
  //         ticket: liscop,

  //       })
  //     }
  //   })
  // },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(e) {
    console.log(e);
    if (e.data == 'null') {
      this.setData({
        VALID:'',
      })
    }else{
      this.setData({
        VALID:e.data
      })
      if (e.data == 0) {
      
        wx.setNavigationBarTitle({
          title: '待付款'
      })
      }else if(e.data == 1){
        wx.setNavigationBarTitle({
          title: '进行中'
      })
      }else{
        wx.setNavigationBarTitle({
          title: '已完成'
      })
      }


    }

    



  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

    this.setData({
  
      session_key: app.globalData.session_key,
      CUSTOMER_ID: app.globalData.CUSTOMER_ID,
      jiami: app.globalData.jiami,
      OPEN_ID: app.globalData.openid,
 
  
    });
    console.log(this.data.OPEN_ID);

    this.search()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})